Fix 'missing function dbg' error

functions were defined in a conditional block after use.  Move the function definitions out of the if ... block to fix
Document required permissions on temp directory
Fix 'undefined variable output' error

Partial fix for Issue #21
fix typo
Fix undefined index 'message'

part-fix for bug #21
fix typo