generalized for different bin numbers