Minor improvements and refactoring.