Refactored/cleaned reducer.py