Fix bugs in reduce and arrayify