fixed issue 1366, minor rewrite in retrieve, thanks Dominic