Fixed team query implementation