Added missing update-document calls
Added on-start hooks and color- and glformat-caching
Split up giant function into smaller ones