Refactored Emily's fabulous work

Modularized. Added a lot of comments.
Read the beginning for a possible idea on the theme.