optimze the lookup logic