Rewrite with tests and async