patch from #222.  Manually applied to new code layout