Added a new test with plotting and fixed some bugs