added mutex for debug function