Move fetching functionality to lib file