Moved the retrieval of the data into a separate function