A thought: it would be nice if there was a top-level function or a static method for this (that this could then wrap) that would be more easily unit-testable.