Implement aggregate_frames function