Refactor HeadAlgorithm.
Refactor Layout.