Bugfixes for crashes