switch tests to chai, fix some bugs