incorporated fixes from John Bachman