Fix reopened hint files not finalized

And some minor refactoring and removal of debug function.