fixed errors in renderImage for loops