Ukkonen's version 2