Various fixes in JS. Better handling of errors in DB