Fixed bugs causing script to not run