refactor the whole type switch thingy