Updated the code for adding matches so that if a match is forward the program backtracks