Code improvements

Some code moved around, some improvements
Documentation improvements
Moved documentation to be interspersed with code
Renamed EMPTY_FORM to EMPTY_FORMAT