fixes to segfault errors