Cleaned up reduce, added comments