moved $where search update before DB quering
moved $count after DB and file results merge