Fixed 'writeTemplate'.
Added error handler to 'writeTemplate()'.