moved unneeded code out of try blocks