Rewrite connected texture code