changed query structure, added file dump functionality