optimize word lookup code