removing the plot modal at the correct time