New Algorithm for case 2 and case 3 works