fixed bugs with entity query