rewrote script a bit