fixes invalid reference to temporary
misc cleanup