refine code & fix some memleak issue
add test code