Cleanup

Major polish and type checker pass.