Minor bugfixes

Some misc. stuff found during performance optimizations.