More changes and refactoring