Refactor some Analytics logic into modules