JS: added error handling