modified pb generation code, fixed small bug