fixed bus errors + segfaults