Implementing solution 3. Fixing warnings in solution 2.