Added some additional error handling.