fix potential segfaults