Move tempname to function