improved tests and fixed bugs