refactor plot