finish the retrieve function