Completed and partially tested the script is in a working state.