modified script a bit to account for some errors