Fixes potential crash. Closes #372