Improved nested case in display() function