Added some file format flexibility to loadData, did some refactoring