Fixing count query.
Adding tests for simple and advanced queries.