new solution to problem #2. minor changes to solution #1