BUG 3 algorithm