fix some seg fault issues