refactor variable names and scope
bug fix: don't clean hooks when enter out of scope