Expression tree transformation and fixing a few bugs in query generation.