minor fix in stateFlatMap