refactored button functionality