refactoring main for better readability