Refactor filetools