Moved some methods to extra module.
Added some tests for query interface.