Moved reduce process outside the core loop
Code cleanup