Refactoring R files and cleaning data