ported binning improvements from BEAM 5 branch to this branch for usage on Calvalus