intermediate commit
forgot to add some files
Major overhaul. A lot of bug fixed. Now the two implementations behave identically.