Refactor utility code to utility module