Added more exception handling.