The case 1 is working but needs optimization.