Some refactoring and tinkering.