#1815

Fix for issues mentioned by @c0bra in #1815
Adding fix for issue #2117 to the PR