Better kpt_index subroutine