[bugfix] Expression state not properly reset throughout function calls

This may result in issues if a query is reused from the pool.
Should this flag not be moved down to the end of this function, i.e. after the state has been beset?