main.cpp refactor