Improvements and refactoring 1.