defer only works in scope of a function