Changed the if else statements into one switch function