Big cleanup, small refactor