moved the binning stuff here to make it self contained
cleaned a few things