Replaced all reading/writing from text files by hdf file. Minor other
changes and tidying up.