Improvements and code refactoring