Async Handling: The await keyword is now correctly used in the function, and the function itself is marked as async.
Modal Handling: The modal is opened asynchronously using await, and the result is processed without using yield.
Error Handling: Both in the main try-catch block and inside the modal handling, errors are caught and handled gracefully.
Helper Functions: I’ve moved some of the common logic (resetting flags, handling click-based actions) to helper functions (resetClickStates and handleActionsBasedOnClickStates) for cleaner and more modular code.