updated connected cells detection algorithm

updated connected cells detection algorithm