fix bug and add df algorithm