Finished but untested 2d implementation, uncompiled