fixed bugs and tests