Made binary merge on the code to make it more efficient