extracted bin mapping algorithm to separate method so that it can be optimized and reused