moving fetch logic to a function