refactor pb.py