helper functions for (de)serialization