correcting indexJ, implemented foldJ