updated case statement to store the result in a variable