Refactoring and small changes