More thorough refactor