BUG 2 algorithm