Bunch of bugfixes here and there.