clean up code, replacing "by" function with "aggregate"