refactored the isInvalid method to check a cell