Moved variable declarations to top of core function.
Noted escape key event block with comment.