Improved namespace detecting in constructor