ensure string zero termination
remove redundant variables