refactor using fold concept.