clean up loading code