Organizational refactoring

Cleaned up transformDocument operations, element handling operations,
options, global referencing, comments, function names