Fixed segfaults and other runtime issues.