replace if statements with a single switch
updated version