How to optimize the following code

Printable View