Remove and sort namespaces