First round of bugfixes