refactor summary queries to eliminate unucessary queries