Converting ad script to an asynchronous version