updated script significantly