Refactoring and main method