Better query cleanup in parse.py

Also make it accept file on command line