Moved lines management to state to fix bugs in the vertical mode.