Added comments in code. Improved TP matching.