fixing bug in final plot