Tweaks and refactoring.