Rewrite to async code