restructured and pulled in the callback function