example:
https://github.com/mobos/mob/blob/master/apps/mob/src/mob.erl#L124-L134
why do you pass around state? probably you can extract from the state the variable you need in the previous function.
Benefits:
- clearer function
- you don't have to return a state that is the same as before