Code fix for replace-doc command. Add missed return prev for reduce