Optimized the print code [fewer lines of code for loops]