Adding some error handling in main.