made much more general, but still not quite working in 2D