added tests, fixed segfault