Replaced reduce with fold-left and fold-right