Added a tiny bit more exception handling.