add code from Bakul for fix to kap(), kapn(), and kapn_()