kabi.c: simplify and cleanup

Also fixes a bug in the substring() routine by removing it altogether
and replacing it with a simple index into the string.