perf improvements on rendering and db query