Use a promise to make sure the function doesn't return too early