Added some error handling.