Updated algo to fit updated lib