Fixes and a bit of refactoring.