create formatResult function