fix bug on case 2 and 3