Updates to document class, added a bunch of memory saving stuff to shared so that common methods are shared amongst classes that use them