Re-factored interaction between modules and main.