wrote the logic for retrieve