dct: refactor all recursive functions