Fix gapi error, improve script loading with promises