make defer function workable