Refactor the main body

Breaking out the read / parse / write code