Refactoring to put the weirdness in specific functions.