Fix bug that causes a segfault in certain cases.