refactor switch logic into a module