Add comment
Seperate handling of a key press
Add missing declarations
Fix return value of handlekey
cleanup
add comment
Major code cleanup, removed unneeded structs, added checks and comments