Fixed bugs in plot functions