using flatMap to replace for comprehension to understand for comprehension in the state management context better.