Simplifying subtotal code