refactor to use async APIs