I don't know how to refactor the code in the way your suggested, as the two if clause "if current_cmo in [xxxx, yyyy]" were different. The best thing I could do was to reorganize the code in a way that looks like what you suggested.

Please have a review. If it's still not what you wanted, please feel free to create a separate patch (with your own Signed-off line) on top to fix it. Thanks.