changed plotting code and added variables at start of script