restructured code to allow use of other serializers