Add test script, minor bugfixes.