factor valid cell index logic
refactor cellc
abstract, cleanup and document

Separate the methods that actually insert dom element for easier
testing.

Cleanup, and order methods more logically

add "docstring"
simplify logic
remove unused/not working function
fix i/index in move up/down and == -> ===
fix one more == to ===
Merge pull request #2929 from Carreau/cleanup-cell-insertion

Cleanup cell insertion