Refactor and cleanup wizardry.