Extract logic into files