Various bugfixes