Refactoring and other changes