draft revision to rebin code