detached the parsing part from query routine to a separate compile routine, and fixed a few other things.