modified to terminate instances