Improved nested lists solution