Refactor, plus store these values rather than checking them twice.