added tests, minor bugs fixes