Started refactoring into utility functions.