Separated some logic out into class modules.