Refactoring the code, plus input stubbed out.