change 0 to '\0'
delete dead code
shorten code by merging two loop