now forming cells row by row. Fixed input range checking