Revert "Revert "added fix to segfault""

This reverts commit 067d20a49815381037dba5478baddfd897d638a6.