Factor out handle_button_press()