Bug fix: Encoding before escaping

The query is now encoded after it has been escaped