extract logic into its own files