more error handling, added template hack for jsduck (need to create real template).