Added error checking when clicking buttons.