working, g(r) runs out of memory on large datasets