a few final bugfixes, and it seems to work