fixed segfault, should fix using iterator