Ported the fixes from yarrowtest and added more tests.