Finish off initial version of script that works.