Added some exception checking