refactored reduce.cpp, removed unused code