Added some more error handling.