Minor cleanup

Organizing transformDocument operations into separate functions for
easier profiling and convention