edited code to make asynchronous calls inside a callback instead of inside a helper function
edited code to make asynchronous calls inside a callback instead of inside a helper function