Serialization, performance improvements

Still needs refactoring