operator[] is working but giving the wrong output