Refactoring part of main() to separate function.