fix tests, address some bugs