Fixed getkey function