Refactored listener for buttons