Updated error handling on main.cpp