keypress improvements + code simplification + refactor