added balanced folds function