Change order to setting wd to before clearing out objects