Minor fixes and cleaning, refactoring.