proper placement of defer