Fixed various issues in unittests and doctests.