Added more exception-handling code