That looks like a nice general solution from @GoForSmoke for handling a list of actions with with a definable time interval between each action. It also matches the behaviour of the existing code, with the exception, of course, that the function sms() must now be called multiple times.
However, if the OP wants to test the return code from each command and immediately continue with the next command as soon as he gets the expected return code, then he has more work to do.