solution with comments