Completely rewrote script