Refactored utility code.