Fixing bugs in plotting code