Added more exception handling