Added dimension adjusting algorithm.