fixed memory leak issue, and optimized rendering loop.