Added code for case 4 and 6