Heavy refactor: use safe duktape call and log caught exceptions