Refactored caseReduce to use some GHC functions.