Testing, fixing and cleaning various small issues.
Fixing some unit tests that failed and solving issue #321.