Fixed small bug on query