Implemented custom serializer for external types, some code cleanup