Updated layout algorithm.