Greater refactor.

It turned out that the former approach was not
ready for dealing with tables with spanning cells.