Refactored some python and added an R-script