rewrote script because it was broken