caught edge cases in case 3,4,and 6