partial implementation of writing out derivative to file