Made a mess while refactoring and fixing

More work on module imports/exports, simplified some type case classes,
etc.