replaced if-else statements with switch statement for buttonReleased function