added more error handling in main