Fixed minor bugs, mostly caused by namespace problems.

There are 3 commits in the pull request. See the respective commit messages to understand each of them.