Refactor out utility functions