Rendering improvements

Improves render times a lot. Frees unused memory and reduces memory foot print a lot.