Problem with case when else statement and casting