Consolidate the button handling in one place.

General clean up and prettification.