Fixed some serious bugs to make it work to demo 2.