Some refactoring and added match group timestamps.
Some more function simplification and refactoring.

To make the code a bit more easy to follow.
Calculate the match group id.