Updates to main.cpp to enhance termination.