Fixed and optimized namespace check