Refactored serializer

Now doesn't use outer object. Cleaned up implementation quite a bit.