Fixing self references to avoid potential segfaults