algorithm updated to v 3