Added a bunch of unit testing, along with cleaning up some of my terrible code

I was using threading badly, I have corrected some of this to give  a
smoother look to the graph, and just better usage of resources.