refactor method loop