fixes #461 and a potential segfault
Merge pull request #462 from mikeferguson/fix_461

fixes #461 and a potential segfault