calculate_aggregates function clean-up
corrected dev(); fixes #1