Various small bugfixes

Fixed various small issues from crash reports.