Separated rendering code for each mode and added caching for render geometry.