Fold function
Implementation for enhancement #16