moving stuff to use defer