stupid rebinning code