[Improvement] Refactoring of Main Module

Some subtle code improvements...