fixed plotting code