Refactor reduceFunc to reduce indentation levels.

Instead of if condition { doThings }, use if !condition { return nil }
doThings.
There should not be any semantic change.