Fix namespacing issues and clean the source a bit.