Move error checking functions to a separate header.
Add new test: counting occurrences of specific branches.