Remove duplicated code when converting table and rows