refactor to pattern