Mostly working version using some asynchronous tricks