Bugfixes, tests now run (almost...)