Rewrite type model

I think this type model is a bit more robust and lends itself to more
readable code.