Refactored the fix for #2043: nil/false namespace

This is a refactored version of the commit 9326cb35ba9ebcdcc512548b73f56c73a5968556 that fixes the issue presented in #2043.