another tweak to the lastIndex position calculation
lint and a little cleanup