more unittests and misc. bug fixes