refactor defer