refractored grid logic into grid class and added validation against inner grid