Updated reduce procedure
Base reduce algorithm