Functions responsible for handling key pressing and releasing improved