Added some basic error handling.