more cleanup and documentation of type system