Separate events, logic, and drawing code into functions