Refactors serialization in separate classes

This is in preparation for adding json serialization

@petebrowne