Added debugging features.

Added a function to only log messages when debugging is enabled. Added
some comments. Moved template functions into a different area. Clearly
identified 'your code goes here'.
"Your stuff here" clarifications.

Made the split between template and script settings, functions and code
even clearer.