implement defer funtion