Refactoring and tidy