Refactor
Refactor
Bug fix and add debug print
Implement look ahead