refactored method main