added cell detection function