Added more documentation and tests to templates.  Changed things around the code slightly in the hopes of making it more readable