Added ability to try and refit N=500 times if the original fit didnt resolve errorbars. Also added a close statement to stop memory leaks during plotting