some clean-up, decided to leave type switch in, though ugly