Implement awhile version of reduce