Revert "simplify the previous fix"

This reverts commit 75ceaf79971550e78045ea185c3b8b95c6485c26.
Revert "fix memory leak"

This reverts commit 38ac67d78c04ba4527df6cdb4a2210b24064d2b4.
don't mess up the expected behavior