Optimize the codes to clean warnning. Also add foreach loop for string writing.