Refactor main.cpp