General code cleanup, refactoring, and commenting
Start documenting the API and templating system