optimize connected textures logic