updating to set directory before invoking k commands. should fix #22. This code needs some help because code is duplicated