refactoring and more code