fixed entity search
some minor refactorings