improved preaveraging script