added an advanced version which use searching