finalized serialize_species function