finished 2d implementation