Fixed a bug in retrieval function