should not have stayed up so late last night
it's ugly, it's cumbersome, but I'm pretty sure it works'
fixed up some bugs that made script not work. might work now