More core JS

Improved exception/error handling, added console for browsers without
console. Improved API caller