finished plot script. not perfect, but should be good enough.