Fix incorrect attribute.
Optimize loop and simplify logic.
Optimize tile stretching.