Added memory of last search, logic to prevent repetitions
Better comments