Completed the function stubs.

Added code and comments to each of the function stubs, and documented
what each function does.