Added some more exception handling