Fixes #5283 and #5315

All it took was some fancy switches.
Merge pull request #5316 from Jarcolr/master

Fixes #5283 and #5315