Cleaned up and commented.
Implemented function declarations.