Added a shutdown clause to the main() function