Fix bug in query() method
Add support for custom namespace