Completed code for aggregate examples