defer only triggers at the end of the current function, which is not what we want in this particular case.