Fixed leaked global function, and a new BUG detected