Fixing bug in except statements