extract logic from Main for all modules