Refactor utilities and make tests use the new utils (tests not passing yet).