enhanced saving to mat/h5