Additional refactoring: use namespaces, chance include guards, etc.