moved upwind state to a function