Made query functional