refactoring and make it executable