change substr() to substring() for performance
a jsperf comparing the two: http://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/14