Refactoring main.cpp