Fix namespace filtering

I've added a handful of tests. The last two tests currently fail, but I think should pass. In order to pass, my second commit fixes what I think is the issue.

Thanks, and feedback encouraged!