Fixing cache problems and threading

Improved rendering performance by getting the processing
out of the render loop