With David's suggestions on mapping and aggregation

Much succinct code