Part 2 of the UI work: Better event handlers and code structure. See Todos.