Ukkonen's version 3