D3d cleanups and improvements