Some bugfixes and changes