renamed query_file + some trivial fix and error checking