Move key handlers into main loop (close #8)