refactoring and better query
minor