Various bugfixing