Bugfixes.
Added test code.