Again, pull this out into a testable pure function.