Use promises to simplify async logic