My solution with more comments