Move mode handling into separate classes