added closestk subroutine and some ugly test outputs