gen khepri file. Cleaned up internal implementation a bit.