furthre mods to make grating work
still not done refactoring for gratings.