Mostly done, but still some bugs to fix