refactor file reading to be asynchronous and change some error reporting