pulled in fixes from #256 instead of my heavy-handed attempt.