Had to make some changes to get it to run again. Please review in case I break something else with this.