Improved namestring handling and other cleanup