All sorts of bugfixes