A bit of refactoring, plus a sanity check