added a base serializer
Bug fix and moved serializer code around