Improve robustness and allow external static calls for debug.