DDTMs working finally, also function rewriting