Trying to get to have all the cubes of the same type together

Right now it does gather the cubes together but the order is not
appropriate. Therefore a new appropriate logic should be applied.