Ukkonen's version 4