Bugfixes

Fixes #685, #1796, #2722, #2977, #3129
Maybe fixes #1836, #3162