modified code for scalar-function-scalar simulation