This should be a switch case block, not if-else, and I don't think we should be be using `typeid()` here.  Or we should have a mapping from typeid to int.  Not a big enough deal to block this PR, but we really should abstract the type system here.