Solved Problem 2
Added testing, gave a shot at Problem 3 but it poses interesting challenges.