re-usage function in loop