A bit of tidy up
Move "state" variable into a scope spur to the try statement