A bunch of bugfixes