Added GRID as a separate class and changed the way gain factors are calculated