completed script for Plot 3