improved script from so tips