fixed bugs, updated tests