optimized rendering speed code needs refactoring.