Changed if statement to case statement