eliminate repetitive functions in loops