Refactor pegex stuff into the proper place