Function may be called reentrantly -> using global temp is wrong