see my comment on line 151 below.