Bug fixes in loadFile function