Fixed the failing unit tests

This pull request fixes the failing unit tests. See the separate commit messages for more info on what and how these fixes were implemented.