added Sergey's fix [plt.close()] to the other functions as well.