Remove unsafe debug func and remove unused code