Bugfixes, small code changes