Fixed b_io to properly read, and reorganized code