improved b_* functions used by ai