Revert "Revert "bugfixes""

This reverts commit 4386cf2612c9e262c7d6e0cc9c91b21576daa215.