fixed bugs and added tests for plotting