working on kaplan-wald code