added tests, some fixes