Cleaned up error handling on keypress