Refactoring & new test cases

Refactored the binning functions and added test cases for them