fix bugs, fix tests