Added more exception and error handling