Added some more fail on errors, an additional try-catch block and some flush:true. All seems to work now