fix scope issue to fix membug
update debug strategy
add API test
update to valgrind script
add parens to make compiler happy