Massive speedup. Now works OK.