Refactor Query object; failing tests