Fixed some bugs with BPB writing and logging.