Minor improvements + refactoring.