Modified to resemble code from RetrievalService