moving success callback into a separate function