refactorung in queries, better count queries performance