Added some exception handling.