refactored out into a query