Fixed bugs in previous version and added main process.r file