Fixed filename propagation bug on rewrite, and fixed this/self typo in query checking