bugfixes; passes basic test