I think what you're trying to do here is create a priority system for targeting within a macro. I'm sorry to say you just can't do that. A macro like this will execute each command in sequence. That's why it's cycling through targets like that.