Possible fix for Issue #977

Please test the change, I have tested it in my current project the queries work fine? Do we really need a $this reference in the function?