Moved functional code from button handlers to own methods.