Fix defer errors