aggregation code added. not sure if it works though