Update algo to accommodate repetitive cases