tweaking algorithm. working on decrementing the array after match