Solution to challenge 3, with help from the internet