Finished solution to week 3, not the most elegant solution