Fixed warnings and segfaults.