improve plotting logic