fixed bugs, improved tests