Added lock for debug output