Added a half-completed version of the third answer, and made some minor changes