fixed some bugs in plotting