factor out peg, use bnf