move defer to better place