Added source file.
Added some documentation.
Moved some code around so the public functions are all at the top.