Enhanced script to compute XGE and B from n&k