[M] Refactored the code in the main.cpp file.