Completed script; See header comments in main.py