Bugfixes

Fixes for the following bugs:
 * 5836
 * 5923
 * 6170
 * 6171
 * 6172
 * 6173