Takes into account dimension updating.

Todo: clean up.
Remove image insertion to cut down complexity.