Cache category graph creation (it's slow!)
Some serialization code refactoring.