Added error handling
Updated error handling further.