Fixing the 3d optimization