wrap the costly operation in debug

Profiling the master and found that the toString is one of the most costly operations, so hiding it behind debug check