Compiler docs and tests

Here are some more compiler docs and small refactorings I've been working on.