added defer function