Simplified the code

Added a new sub that controls the buttons.