added test code. bugfixes.