Split main logic into it's own module.