added more robust error handling to scripts.js
added more robust error handling to scripts.js