refactoring and tidying