I would have dealt with this in the same condition below (line 102) and set the type there when pos is 0.