Revert "Revert "Replaced if statements with switch statement.""

This reverts commit b4b62b9ae1be12d5e9cb2441ac74454fd8f9f9e1.