Fixed some performance issues in the render function. Running well in Chrome, but still really slow on Firefox (32bit Ubuntu.)