minor corrections & agg function added