begin to rewrite bip.c/h, make it more flexible