Adding support for query scopes, fixing bug in test