replaced switch with if else