reformatted main.r