Code refactoring, minor enhancements