Refactor file building