wrote a function to null terminate