Added necessary code for functionality.

Added the code and comments required for these functions to fulfill all
the requirements listed as well as explain what's happening.