Refactor e debug