I'm not entirely familiar with raw MODE changes, but I believe you have to check any and all modes in the MODE raw against the list of user/channel modes given by the server when you first connect (I don't know the RAW of that list, probably 001-005). That will tell you whether each mode (character) needs to use one of the arguments provided after the mode characters. ie

:nick!ident@host MODE #channel +os-v targetnick1 targetnick2

= mode characters
= arguments

In the example, mode +o (ops) requires an argument and consumes the first nickname provided. Mode +s (secret channel) doesn't require an argument, so it doesn't use up one from the list. Mode -v (devoice) requires an argument, so it consumes the remaining argument given.

The server I am presently on, doesn't use this method (precisely). Instead, it arranges the mode characters so that if n arguments are provided, the mode characters associated with those arguments are last in the string of mode characters. Example:

/mode #channel -hC+Rv targetnick1 targetnick2
:nick!ident@host MODE #channel +R-Ch+v genius_at_work genius_at_work

You can see that the server rearranged the modes so that the two requiring arguments (-h and +v) were last in the mode character string. Because of the modes I chose to set and unset, the server had to do + modes twice.

Your script should take these two possibilities into account if you plan on using it on more than one server.

-genius_at_work