Moving DOM write to outside of loop (better performance)