use defer instead of variable for function