JS refactor for Grid dynamic sizing and DOM creation