refactor and better document the compiler class

- complete docs for all functions
- move more functionality to private functions
- clean up some difficult to understand and/or messy code