Code cleanup

Moved key handler code to function getKey()
Removed unecessary code