moving state to function parameters