Fix issue #173 to prevent some crashes