Updated version of js-template.js with improved error logging