full implementation of search and retrieve: needs more testing