finished two dimensions
added 3d and general n dimensions