Various bugfixes, minor changes