basic algorithm written for binning; need to test