Refactoring quick outline (not finished).