A little refactoring before sharing this.