cleaning up from_hdf5 code
Removing code duplication