Refactor pickling helpers into a separate module