refactor the dfrom and clean code