Moved grid computation into layout module.