fix potential memory leak/bug
fix previous commit and add test