Completed challenge 40. Made minor changes to challenge 39 for consistency.