Another messy commit with many changes

changes to pb.py and referenceable.py
changes to some unit tests