add test & eliminate memory leak