Fixed error with reduce function