Fixed checkCellState function