Added some basic exception handling.