Added ending condition to MainDriver