optimized contact retrieval algorithm