moved the button handling out of the main