update script to be more percise to reduce memory usage