Fixed a couple important bugs that caused reference errors and scripts not executing