refactored queries for totals on baby matrix