fix pretty printer by adding finalNode; add fail case