fix defer code