Cleaned up the code a bit and moved a few classes into different
namespaces.