I found that if I just use open_new the kill task does not work (for unknown reasons), but if I use open_new_tab this seems to work, although it struggles when trying to reopen, so a short sleep after the kill may be helpful (even if only 1 second).
Also I can't help but notice that you are adding zero to a each time through the loop is this meant to be +1?