Some changes and refactoring