Optimised the loops of text.js