fix the first input issue & print the last entry also