Added exception handeling and a better test script
Added exception handling