Worked on the assembly of the output string and manipulating array based on key