nested switches make me queezy, would it be better to extract a function for each state?