Simplify pascal code
Simplify balance code with match stmt