Final solution2 with comments