refactoring addCell method.