Added keypress detection functionality
Fixed several bugs