refactored queries a little