Implemented fold operation