restructure and add tests for dual forward AD