One thing notice is that there's no debouncing with the keypad reading. That may cause unreliable input.
Rob