Fix partial name with namespace

Because namespace assignment was occurring after dir = dir.dir,
there was never a dir.namespace. Had to put namespace before dir
get its new value.

Also went ahead and added some unit tests