Generalized code, implemented PBM loading/export.