Incorrect handling of URC commands

Hi, I am trying to implement URC and QIRD commands for my application. All my commands are processed through a queue mechanism. Before I send a new ATCOMMAND, i always clear the buffer, to prevent any overflows or data corruption. As a result of which what is happening is, if there are URC messages, they are not getting detected or parsed correctly. Another case is for multistage commands like QISEND, where the application has to wait before the > prompt comes, is there a chance that any URC message would come through in that interval.? What is the correct way of handling these messages? I am using an async statemachine based approach for the command handling.

when the > prompt comes,If there are other URCs including the received data, will be cached, wait > input data, other URCs will output