fix fold function