fixed refence counting segfaults