Added an implementation of reduce