fixed write bif to wirk with the terminal. Ugly stuff with a global but works for now