Change the code structure
Fixed appending empty row at the end of final array