fixed big bug in plotting code