Initial implement of Algorithm 4