Reformatting code with proper spaces indention, other cleanup
Move MatchRule detection so it reads it properly at the start if the input
It currently reads it for every separate part